/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.jvm.zhuangtaiji._2;

import org.squirrelframework.foundation.fsm.StateMachineBuilder;
import org.squirrelframework.foundation.fsm.StateMachineBuilderFactory;

import static com.azdebugit.jvm.zhuangtaiji._2.Event.*;
import static com.azdebugit.jvm.zhuangtaiji._2.State.*;

public class TestMain {

    public static void main(String[] args) {

        StateMachineBuilder<StateMachine, State, Event, Context> builder =
                StateMachineBuilderFactory.create(StateMachine.class, State.class, Event.class, Context.class);

        /**
         * 状态转移表
         */
        //F(APPROVE,APPROVE_PASS)->(PASS,approvePassAction)
        builder.externalTransition().from(APPROVE).to(PASS).on(APPROVE_PASS).callMethod("approvePassAction");

        //F(APPROVE,APPROVE_REFUSED)->(REFUSED,ApproveRefusedAction)
        builder.externalTransition().from(APPROVE).to(REFUSED).on(APPROVE_REFUSED).callMethod("approveRefusedAction");

        //F(REFUSED,RECHECK_PASS)->(PASS,RecheckPassAction)
        builder.externalTransition().from(REFUSED).to(PASS).on(RECHECK_PASS).callMethod("recheckPassAction");

        //F(REFUSED,RECHECK_REFUSED)->(REFUSED,RecheckRefusedAction)
        builder.externalTransition().from(REFUSED).to(REFUSED).on(RECHECK_REFUSED).callMethod("recheckRefusedAction");

        StateMachine machine = builder.newStateMachine(APPROVE);

        Context patchouli = new Context(" patchouli ");
        Context xiaoye = new Context(" haha ");

        machine.start();

        //patchouli审批拒绝
        machine.fire(APPROVE_REFUSED,patchouli);

        //xiaoye复核成功
        machine.fire(RECHECK_PASS,xiaoye);

    }

}
